<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<f:view>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <link rel="stylesheet" type="text/css" href="css/dataTable.css" />
            <link rel="stylesheet" type="text/css" href="css/messages.css" />
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Simple Forum</title>
        </head>
        <body>
            
            <h:form id="headerLinks">
                <h:commandLink action="categories" value="[back to categories]" />
                <h:commandLink action="login" value="[logout]" style="padding-left : 55px;" />
            </h:form>
            
            <!-- Topics -->
            <h2>Topics</h2>
            <h:form styleClass="jsfcrud_list_form">
                <h:dataTable value="#{forumTopicController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">                  
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListCategoryTitle_name}"/>
                        </f:facet>
                        <h:outputText value="#{item.topicId}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListCategoryTitle_name}"/>
                        </f:facet>
                        <h:commandLink action="posts" value="#{item.title}">
                            <f:setPropertyActionListener target="#{forumPostController.topic}" value="#{item}"/>     
                        </h:commandLink>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListCategoryTitle_description}"/>
                        </f:facet>
                        <h:outputText value="#{item.username}"/>
                    </h:column>            
                </h:dataTable>
            </h:form>
            
            <!--Add Topic -->
            <h:form id="addTopic">
                <h:panelGrid border="1" columns="2">
                    <h:outputLabel for="text" value="text:" />
                    <h:panelGroup>
                        <h:inputText id="text" value="#{forumTopicController.selected.title}" required="true" label="#{msg.text_label}" >
                            <f:validator validatorId="DuplicatePostValidator" />
                        </h:inputText>
                        <h:message for="text" infoClass="infoMessages" errorClass="errorMessages" />
                    </h:panelGroup>
                    <h:panelGroup>&nbsp;</h:panelGroup>
                    <h:panelGroup>
                        <h:commandButton value="Add Topic from #{user.username}" action="#{forumTopicController.create}" >
                            <f:setPropertyActionListener target="#{forumTopicController.selected.username}" value="#{user}"/>
                        </h:commandButton>
                    </h:panelGroup>
                </h:panelGrid>
            </h:form>
        </body>
    </html>
</f:view>